package org.xxmi.cors.common;

import org.springframework.util.StringUtils;

/**
 * 文件工具类
 */
public class FileUtils {

    /**
     * 获取文件名
     * @param fileName 文件全名包含后缀名
     * @return
     */
    public static String getFileName(String fileName){
        if(!StringUtils.isEmpty(fileName)){
            int lastIndexOf = fileName.lastIndexOf(".");
            if(lastIndexOf == -1){
                lastIndexOf = fileName.length();
            }
            return fileName.substring(0,lastIndexOf);
        }
        return "";
    }

    /**
     * 获取后缀名
     * @param fileName 文件全名
     * @return
     */
    public static String getSuffixName(String fileName){
        if(!StringUtils.isEmpty(fileName)){
            int lastIndexOf = fileName.lastIndexOf(".");
            if(lastIndexOf == -1){
                return "";
            }
            return fileName.substring(lastIndexOf);
        }
        return "";
    }

    public static void main(String[] args) {
        String suffixName = getSuffixName("1234.x");
        System.out.println(suffixName);
    }


}
